package com.acg.security.custom;


import com.acg.util.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * 密码验证类
 */
@Component
public class MyCustomMd5PasswordEncoder implements PasswordEncoder {

    /**
     * 对用户输入的密码进行加密
     * @param rawPassword       用户传递的密码
     * @return
     */
    @Override
    public String encode(CharSequence rawPassword) {
        return MD5.encrypt(rawPassword.toString());
    }

    /**
     * 比较数据库密码和 用户输入两者是否相同
     * @param rawPassword the raw password to encode and match
     * @param encodedPassword the encoded password from storage to compare with
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {

        return MD5.encrypt(rawPassword.toString()).equals(encodedPassword);
    }
}
